package com.ems.controller;

import com.ems.service.IBatteryVoltageService;
import com.ems.vo.BaseResult;
import com.ems.vo.BatteryVoltageVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 电池电压 前端控制器
 * </p>
 *
 * @author WuZH
 * @since 2024-04-23
 */
@RestController
@RequestMapping ( "/batteryVoltage" )
@CrossOrigin ( value = "*", maxAge = 3600 )
public class BatteryVoltageController {

    @Resource
    private IBatteryVoltageService iBatteryVoltageService;

    /**
     * 查询单体电池所有电压，整合为一条数据结构
     *
     * @param batteryVoltageVo
     * @return
     */
    @RequestMapping ( "queryList" )
    public BaseResult queryList ( @RequestBody BatteryVoltageVo batteryVoltageVo ) {
        List<BatteryVoltageVo> batteryVoltageVos = iBatteryVoltageService.queryList ( batteryVoltageVo );
        batteryVoltageVo = batteryVoltageVos.get ( 0 );
        String[] split1 = batteryVoltageVo.getVoltage1 ().split ( ";" );
        String[] split2 = batteryVoltageVo.getVoltage2 ().split ( ";" );
        String[] split3 = batteryVoltageVo.getVoltage3 ().split ( ";" );
        String[] split4 = batteryVoltageVo.getVoltage4 ().split ( ";" );
        String[] split5 = batteryVoltageVo.getVoltage5 ().split ( ";" );
        String[] split6 = batteryVoltageVo.getVoltage6 ().split ( ";" );
        String[] split7 = batteryVoltageVo.getVoltage7 ().split ( ";" );
        String[] split8 = batteryVoltageVo.getVoltage8 ().split ( ";" );
        String[] split9 = batteryVoltageVo.getVoltage9 ().split ( ";" );
        String[] split10 = batteryVoltageVo.getVoltage10 ().split ( ";" );
        String[] split11 = batteryVoltageVo.getVoltage11 ().split ( ";" );
        String[] split12 = batteryVoltageVo.getVoltage12 ().split ( ";" );
        String[] split13 = batteryVoltageVo.getVoltage13 ().split ( ";" );
        String[] split14 = batteryVoltageVo.getVoltage14 ().split ( ";" );
        String[] split15 = batteryVoltageVo.getVoltage15 ().split ( ";" );
        String[] split16 = batteryVoltageVo.getVoltage16 ().split ( ";" );
        String[] split17 = batteryVoltageVo.getVoltage17 ().split ( ";" );
        String[] split18 = batteryVoltageVo.getVoltage18 ().split ( ";" );
        String[] split19 = batteryVoltageVo.getVoltage19 ().split ( ";" );
        String[] split20 = batteryVoltageVo.getVoltage20 ().split ( ";" );
        String[] split21 = batteryVoltageVo.getVoltage21 ().split ( ";" );
        String[] split22 = batteryVoltageVo.getVoltage22 ().split ( ";" );
        int count = split1.length + split2.length + split3.length + split4.length + split5.length + split6.length + split7.length + split8.length + split9.length + split10.length + split11.length + split12.length + split13.length + split14.length + split15.length + split16.length + split17.length + split18.length + split19.length + split20.length + split21.length + split22.length;
        return BaseResult.success ( batteryVoltageVos, count );
    }

    @RequestMapping ( "saveSingle" )
    public BaseResult saveSingle ( @RequestBody BatteryVoltageVo batteryVoltageVo ) {
        batteryVoltageVo = iBatteryVoltageService.saveSingle ( batteryVoltageVo );
        return BaseResult.success ( batteryVoltageVo );
    }

}
